package com.charles.bigdata.mapreduce.order;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * 自定义比较器
 * <p>
 * 进行比较，前两条数据的订单号相同，放入一组，默认是以第一条记录的key作为这组记录的key。
 */
public class MyGroupingComparator extends WritableComparator {
	public MyGroupingComparator() {
		super(OrderBean.class, true);
	}

	@Override
	public int compare(WritableComparable a, WritableComparable b) {
		OrderBean obj1 = (OrderBean) a;
		OrderBean obj2 = (OrderBean) b;
		return obj1.getItemId().compareTo(obj2.getItemId());
	}
}
